package com.xxl.shoppingapp.ui.main;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.KeyEvent;

import com.xxl.shoppingapp.R;
import com.xxl.shoppingapp.base.BaseActivity;



public class MainActivity extends BaseActivity {

    @Override
    protected int getLayoutId() {
        return R.layout.activity_common;
    }

    private static MainActivity instance;

    public synchronized static MainActivity getInstance() {
        if (instance == null) {
            instance = new MainActivity();
        }
        return instance;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle(getResources().getString(R.string.main));
        getSupportFragmentManager().beginTransaction().replace(R.id.real_content, MainFragment.getInstance()).commit();
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        int i = getSupportFragmentManager().getBackStackEntryCount();
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0
                && i == 0) {

            new AlertDialog.Builder(this)
                    .setTitle(getString(R.string.dialog_title_text))
                    .setMessage(getString(R.string.exit_confirm_prompt))
                    .setPositiveButton(R.string.exit_confirm,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                                    int which) {
                                    // LianLianApplication.getInstance()
                                    // .onReleaseMusicModule();
                                    finish();
                                    // SystemExit(0);
                                }
                            })
                    .setNegativeButton(R.string.exit_cancel,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                                    int which) {
                                    dialog.dismiss();
                                }
                            }).show();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
